import { FetchUserInfo, IServerInfo, IUser } from './interface'
import { defaultPersonalConfig } from '@/api/personalConfig/interface'

export const transServerInfo = (data: IServerInfo): IServerInfo => ({
	jd2000: data.jd2000 ?? 0,
	jd2100: data.jd2100 ?? 0,
	trad_mix: data.trad_mix ?? 0,
	port_mix: data.port_mix ?? 0,
	brand: data.brand ?? '',
	integrated: data.integrated ?? 0,
	has_auth_server: data.has_auth_server ?? 0,
	enable_sm1: data.enable_sm1 ?? 0,
	enable_sm4: data.enable_sm4 ?? 0,
	enable60fps: data.enable60fps ?? 0,
	enable4k: data.enable4k ?? 0,
	enable_kis: data.enable_kis ?? 0,
	enable_room: data.enable_room ?? 0,
	system_date: data.system_date ?? '',
	enable_quantum: data.enable_quantum ?? 0,
	stand_alone: data.stand_alone ?? 0,
	enable_audience: data.enable_audience ?? 0,
})
//平台迁移，需要判断是否有新增的配置，有新增的配置需要额外手动增进去
function deepEqualSet(defaultConfig: any, personalConfig: any) {
	for (const key in defaultConfig) {
		if (personalConfig[key] === undefined) {
			personalConfig[key] = defaultConfig[key]
		} else if (typeof defaultConfig[key] === 'object') {
			deepEqualSet(defaultConfig[key], personalConfig[key])
		}
	}
}
export const transUserInfo = (data: FetchUserInfo): IUser => {
	let personal_config = data.personal.meeting ? JSON.parse(data.personal.meeting) : defaultPersonalConfig
	deepEqualSet(defaultPersonalConfig, personal_config)
	return {
		account: data.account ?? '',
		account_type: data.account_type ?? '',
		protocol: data.call_protocol ?? '', //对应有问题，这个值只有ip设备才会有值
		name: data.name ?? '',
		moid: data.moid ?? '',
		portrait32: data.portrait_bit32 ?? '',
		portrait64: data.portrait_bit64 ?? '',
		work_phone: data.ext_num ?? '',
		mobile_phone: data.mobile ?? '',
		email: data.email ?? '',
		e164: data.e164 ?? '',
		ext_num: data.ext_num ?? '',
		is_meeting_admin: data.meeting_admin ?? 0,
		is_user_domain_admin: data.user_domain_admin ?? 0,
		enable_kis: (data.enable_kis || data.kis_admin) ?? 0,
		enable_video: data.enable_video ?? 0,
		enable_play: data.enable_play ?? 0,
		enable_live: data.enable_live ?? 0,
		enable_dcs: data.enable_dcs ?? 0,
		enable_vrs: data.enable_vrs ?? 0,
		enable_download: data.enable_download ?? 0,
		enable_meeting: data.enable_meeting ?? 0,
		enable_venue_monitor: data.enable_venue_monitor ?? 0,
		enable_cms_approval: data.cms_approval ?? 0,
		cms_virtual_approval: data.user_domain?.cms_virtual_approval ?? 0,
		enable_upload: data.user_domain?.enable_upload ?? 0,
		sso_token: data.sso_token ?? '',
		client_ip: data.client_ip ?? '',
		expired_in: data.expired_in ?? 0,
		machine_room_moid: data.machine_room_moid ?? '',
		enable_hd_meeting: data.user_domain.enable_hd_meeting ?? 0,
		enable_h265: data.user_domain.enable_h265 ?? 0,
		enable_port_media: data.user_domain.enable_port_media ?? 0,
		enable_trans: data.user_domain.enable_trans ?? 0,
		enable_sfu: data.user_domain.enable_sfu ?? 0,
		enable_meeting_sms: data.enable_meeting_sms ?? 0,
		enable_meeting_wechat: data.user_domain.wechat_notice ?? 0,
		user_domain_enable_dcs: data.user_domain.enable_dcs ?? 0,
		user_domain_enable_vrs: data.user_domain.enable_vrs ?? 0,
		personal_config,
		monitor: {
			exe_version: data.monitor.exe_version ?? '',
			linux_arm_ft64_version: data.monitor.linux_arm_ft64_version ?? '',
		},
	}
}
